<template>
  <img alt="Vue logo" src="./assets/logo.png">
  <hr>
  计数器：{{count}} <button @click="increment">自增</button>
  <hr>
  计数器1：{{count1}} <button @click="increment1">自增</button>
  <hr>
  <button @click="toggleShow">显示隐藏</button>
  <div class="box" v-if="show"></div>

</template>

<script>
import { ref } from 'vue'
// 3. 组合API实现  couter 和  显示隐藏 ， 提取复用逻辑
const useCounter = () => {
  // 1. couter
    const count = ref(0)
    const increment = () => {
      count.value ++
    }
  return { count, increment }
}
export default {
  name: 'App',
  setup () {
    // 抽离逻辑
    const { count, increment } = useCounter()
    // 复用逻辑
    const { count: count1, increment: increment1 } = useCounter()

    // 2. 显示隐藏
    const show = ref(true)
    const toggleShow = () => {
      show.value = !show.value
    }



    return { count, increment , show, toggleShow, count1, increment1}
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
.box {
  width: 100px;
  height: 100px;
  background: pink;
}
</style>
